﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace Marmat.Forms.Skin
{
    /// <summary>
    /// 表示 Marmat.Forms.Skin.DirectUIControl 对象集合。
    /// </summary>
    public class DirectUIControlCollection:IList<DirectUIControl>
    {
        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
        private readonly List<DirectUIControl> collection;
        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
        private readonly Marmat.Forms.Skin.DirectUIContainer owner;

        /// <summary>
        /// 初始化 Marmat.Forms.Skin.ObjectCollection 的新实例。
        /// </summary>
        /// <param name="owner"></param>
        public DirectUIControlCollection(Marmat.Forms.Skin.DirectUIContainer owner)
        {
            this.owner = owner;
            this.collection = new List<DirectUIControl>();
        }


        public DirectUIControl this[int index] { get => ((IList<DirectUIControl>)this.collection)[index]; set => ((IList<DirectUIControl>)this.collection)[index] = value; }

        public int Count => ((ICollection<DirectUIControl>)this.collection).Count;

        public bool IsReadOnly => ((ICollection<DirectUIControl>)this.collection).IsReadOnly;

        public void Add(DirectUIControl item)
        {
            item.Parent = this.owner;
            ((ICollection<DirectUIControl>)this.collection).Add(item);
        }

        public void Clear()
        {
            ((ICollection<DirectUIControl>)this.collection).Clear();
        }

        public bool Contains(DirectUIControl item)
        {
            return ((ICollection<DirectUIControl>)this.collection).Contains(item);
        }

        public void CopyTo(DirectUIControl[] array, int arrayIndex)
        {
            ((ICollection<DirectUIControl>)this.collection).CopyTo(array, arrayIndex);
        }

        public IEnumerator<DirectUIControl> GetEnumerator()
        {
            return ((IEnumerable<DirectUIControl>)this.collection).GetEnumerator();
        }

        public int IndexOf(DirectUIControl item)
        {
            return ((IList<DirectUIControl>)this.collection).IndexOf(item);
        }

        public void Insert(int index, DirectUIControl item)
        {
            ((IList<DirectUIControl>)this.collection).Insert(index, item);
        }

        public bool Remove(DirectUIControl item)
        {
            return ((ICollection<DirectUIControl>)this.collection).Remove(item);
        }

        public void RemoveAt(int index)
        {
            ((IList<DirectUIControl>)this.collection).RemoveAt(index);
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return ((IEnumerable)this.collection).GetEnumerator();
        }
    }
}
